package HUZ;

public class demo2 {
    public static void main(String[] args) {
        System.out.println("主线程main，begin");
        Thread t1=new Thread(()->{
            System.out.println("线程t1,begin");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程t1,end");
        });
        t1.start();


        Thread t2=new Thread(()->{
            System.out.println("线程t2,begin");
            try {
                //让t2等待t1结束，就在线程t2中调用t1.join
                t1.join();
                //Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程t2,end");
        });
        t2.start();
        // //让主线程等待t2结束，就在主线程中调用t2.join
        try {
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("主线程main,end");
    }
}
